/*
 * Created on 20/11/2007
 *
 */
package org.seginfo.httpfuzzer.connection.status;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Matu
 */
public class StatusFactory {
	
	private static Map statusMap;

	static {
		statusMap = new HashMap();
		
		/* -1 */
		statusMap.put(new Integer(-1), buildStatus(-1, "No status code available"));
		
		/* 100 */
		statusMap.put(new Integer(100), buildStatus(100, "Continue"));
		
		/* 200 */
		statusMap.put(new Integer(200), buildStatus(200, "OK"));
		
		/* 300 */
		//
		
		/* 400 */
		statusMap.put(new Integer(400), buildStatus(400, "Bad Request"));
		statusMap.put(new Integer(404), buildStatus(404, "Not Found"));
		statusMap.put(new Integer(405), buildStatus(405, "Method Not Allowed"));
		statusMap.put(new Integer(406), buildStatus(406, "Not Acceptable"));
		statusMap.put(new Integer(411), buildStatus(411, "Length Required"));
		
		/* 500 */
		statusMap.put(new Integer(501), buildStatus(501, "Not Implemented"));
		statusMap.put(new Integer(504), buildStatus(504, "Gateway Timeout"));
		
	}
	
	/**
	 * @param code
	 * @return
	 */
	public static Status getStatus(int code) {
		Status status = (Status) statusMap.get(new Integer(code));
		if (status == null) {
			status = buildStatus(code);
		}
		return status;
	}
	
	/**
	 * @param code
	 * @return
	 */
	private static Status buildStatus(int code) {
		return buildStatus(code, new String(), new String());
	}
	
	/**
	 * @param code
	 * @param name
	 * @return
	 */
	private static Status buildStatus(int code, String name) {
		return buildStatus(code, name, new String());
	}
	
	/**
	 * @param code
	 * @param name
	 * @param description
	 * @return
	 */
	private static Status buildStatus(int code, String name, String description) {
		return new StatusImpl(code, name, description);
	}
}
